Visual Basic (Declaration) | |
---|---|
Public Function Dequeue() As KeyValuePair(Of TKey,TValue) |
C# | |
---|---|
public KeyValuePair<TKey,TValue> Dequeue() |
Return Value
The Key/Value pair removed.Exception | Description |
---|---|
System.InvalidOperationException | Raised if the table is unordered |
System.ObjectDisposedException | The exception that is thrown when an operation is performed on a disposed object. |
Library/Library.Test/TestLurchTable.cs
C# | Copy Code |
---|---|
var recorder = new RecordEvents<int, string>(); var test = new LurchTable<int, string>(LurchTableOrder.Access, 3, 1103, 10, 10, EqualityComparer<int>.Default); test.ItemAdded += recorder.ItemAdded; test.ItemUpdated += recorder.ItemUpdated; test.ItemRemoved += recorder.ItemRemoved; test[1] = "a"; Assert.AreEqual("a", recorder.LastAdded.Value); test[2] = "b"; Assert.AreEqual("b", recorder.LastAdded.Value); test[3] = "c"; Assert.AreEqual("c", recorder.LastAdded.Value); Assert.AreEqual(3, test.Count); Assert.AreEqual("b", test[2]); //access moves to front.. test[4] = "d"; Assert.AreEqual("d", recorder.LastAdded.Value); Assert.AreEqual("a", recorder.LastRemove.Value); test[5] = "e"; Assert.AreEqual("e", recorder.LastAdded.Value); Assert.AreEqual("c", recorder.LastRemove.Value); test[2] = "B"; Assert.AreEqual("B", recorder.LastUpdate.Value); test[6] = "f"; Assert.AreEqual("f", recorder.LastAdded.Value); Assert.AreEqual("d", recorder.LastRemove.Value); Assert.AreEqual(3, test.Count); // still 3 items string value; Assert.IsTrue(test.TryRemove(5, out value)); Assert.AreEqual("e", value); Assert.AreEqual("e", recorder.LastRemove.Value); Assert.AreEqual("B", test.Dequeue().Value); Assert.AreEqual("f", test.Dequeue().Value); Assert.AreEqual(0, test.Count); |
VB.NET | Copy Code |
---|---|
Dim recorder As var = New RecordEvents(Of Integer, String)() Dim test As var = New LurchTable(Of Integer, String)(LurchTableOrder.Access, 3, 1103, 10, 10, EqualityComparer(Of Integer).[Default]) test.ItemAdded += recorder.ItemAdded test.ItemUpdated += recorder.ItemUpdated test.ItemRemoved += recorder.ItemRemoved test(1) = "a" Assert.AreEqual("a", recorder.LastAdded.Value) test(2) = "b" Assert.AreEqual("b", recorder.LastAdded.Value) test(3) = "c" Assert.AreEqual("c", recorder.LastAdded.Value) Assert.AreEqual(3, test.Count) Assert.AreEqual("b", test(2)) 'access moves to front.. test(4) = "d" Assert.AreEqual("d", recorder.LastAdded.Value) Assert.AreEqual("a", recorder.LastRemove.Value) test(5) = "e" Assert.AreEqual("e", recorder.LastAdded.Value) Assert.AreEqual("c", recorder.LastRemove.Value) test(2) = "B" Assert.AreEqual("B", recorder.LastUpdate.Value) test(6) = "f" Assert.AreEqual("f", recorder.LastAdded.Value) Assert.AreEqual("d", recorder.LastRemove.Value) Assert.AreEqual(3, test.Count) ' still 3 items Dim value As String Assert.IsTrue(test.TryRemove(5, value)) Assert.AreEqual("e", value) Assert.AreEqual("e", recorder.LastRemove.Value) Assert.AreEqual("B", test.Dequeue().Value) Assert.AreEqual("f", test.Dequeue().Value) Assert.AreEqual(0, test.Count) |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7